Skip to content

fix(Power): refactor EXT_CHRG_DETECT to compile-time macros with pull-mode inference#10191

Merged
jp-bennett merged 2 commits intomeshtastic:developfrom
mesh-malaysia:ext-chrg-detect
Apr 23, 2026
Merged

fix(Power): refactor EXT_CHRG_DETECT to compile-time macros with pull-mode inference#10191
jp-bennett merged 2 commits intomeshtastic:developfrom
mesh-malaysia:ext-chrg-detect

Conversation

@ndoo
Copy link
Copy Markdown
Contributor

@ndoo ndoo commented Apr 17, 2026

Summary

Mirrors the EXT_PWR_DETECT pattern: replaces runtime static variables (ext_chrg_detect_mode, ext_chrg_detect_value) with compile-time macros.

Auto-infers EXT_CHRG_DETECT_VALUE from EXT_CHRG_DETECT_MODE at compile time:

  • INPUT_PULLUPLOW
  • INPUT_PULLDOWNHIGH
  • default (no pull mode or explicit value) → HIGH

This fixes inverted polarity on variants that define EXT_CHRG_DETECT_MODE INPUT_PULLUP without an explicit EXT_CHRG_DETECT_VALUE (e.g. russell): the old runtime default of HIGH caused isCharging() to return the wrong value.

Variants touched:

  • russell — bug fixed: INPUT_PULLUP now correctly infers LOW
  • ELECROW-ThinkNode-M4 — redundant explicit EXT_CHRG_DETECT_VALUE HIGH removed; behaviour unchanged (HIGH is the inferred default)

🤝 Attestations

  • I have tested that my proposed changes behave as described.
  • I have tested that my proposed changes do not cause any obvious regressions on the following devices:
    • Heltec (Lora32) V3
    • LilyGo T-Deck
    • LilyGo T-Beam
    • RAK WisBlock 4631
    • Seeed Studio T-1000E tracker card — pio run -e tracker-t1000-e SUCCESS; explicit EXT_CHRG_DETECT_VALUE LOW preserved, gate now also applies (CHARGER_DET gates CHARGE_STA — semantically correct)
    • Other: pio run -e rak3172 SUCCESS (no EXT_CHRG_DETECT, confirms no regression); pio run -e russell SUCCESS (INPUT_PULLUP auto-inference + gate verified)

@github-actions github-actions Bot added needs-review Needs human review bugfix Pull request that fixes bugs labels Apr 17, 2026
@ndoo ndoo marked this pull request as ready for review April 17, 2026 06:10
@ndoo ndoo changed the title fix(Power): refactor EXT_CHRG_DETECT to compile-time macros fix(Power): infer EXT_CHRG_DETECT_VALUE from pull mode; gate on EXT_PWR_DETECT when defined Apr 17, 2026
@ndoo
Copy link
Copy Markdown
Contributor Author

ndoo commented Apr 20, 2026

I’m going to drop the 2nd commit to prevent potential regressions and reduce the scope of the PR.

Mirror the EXT_PWR_DETECT pattern: replace runtime static variables
(ext_chrg_detect_mode, ext_chrg_detect_value) with compile-time macros.
Auto-infer EXT_CHRG_DETECT_VALUE from EXT_CHRG_DETECT_MODE when the mode
is INPUT_PULLUP (→ LOW) or INPUT_PULLDOWN (→ HIGH); default to HIGH.

This fixes inverted polarity on variants that define EXT_CHRG_DETECT_MODE
INPUT_PULLUP without an explicit EXT_CHRG_DETECT_VALUE (e.g. russell):
previously the runtime default of HIGH caused isCharging() to return the
opposite of the correct value. With auto-inference the correct LOW active
level is now derived at compile time.

Remove the now-redundant EXT_CHRG_DETECT_VALUE HIGH from ELECROW-ThinkNode-M4
variant.h since HIGH is the inferred default.

Signed-off-by: Andrew Yong <noreply@example.com>
Assisted-by: Claude Sonnet 4.6 <noreply@anthropic.com>
@ndoo
Copy link
Copy Markdown
Contributor Author

ndoo commented Apr 20, 2026

Commit dropped and rebased on develop

@ndoo ndoo force-pushed the ext-chrg-detect branch from 20556ec to 7cfc4eb Compare April 20, 2026 13:22
@ndoo ndoo changed the title fix(Power): infer EXT_CHRG_DETECT_VALUE from pull mode; gate on EXT_PWR_DETECT when defined feat(Power): infer EXT_CHRG_DETECT_VALUE from pull mode Apr 20, 2026
@ndoo ndoo changed the title feat(Power): infer EXT_CHRG_DETECT_VALUE from pull mode fix(Power): refactor EXT_CHRG_DETECT to compile-time macros with pull-mode inference Apr 20, 2026
@jp-bennett
Copy link
Copy Markdown
Collaborator

I started working on Power.cpp, and found myself making exactly these changes. =D Will pull so you get credit.

@ndoo
Copy link
Copy Markdown
Contributor Author

ndoo commented Apr 23, 2026 via email

@jp-bennett jp-bennett merged commit 2ed7bba into meshtastic:develop Apr 23, 2026
78 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Pull request that fixes bugs needs-review Needs human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants